//
// Created by jack on 2021/2/5.
//

#include "weilapb_defines.h"

#include <WL.Service.pb.h>
#include <pb_encode.h>

#include "weilapb_datafuns.h"

#include "weilapb_group.h"
#include "weilapb_internal.h"

PBEncResult weilapb_buildGroupReq(PB_UINT16 commandId, WL_Group_GroupMessage* pParam) {
    PBEncResult                pbResult;
    WL_Service_ServiceMessage* pServiceMessage =
        weilapb_buildServiceMsg(WL_Service_ServiceID_SERVICE_GROUP, commandId, WL_Service_CommandType_COMMAND_REQUEST);

    memset(&pbResult, 0, sizeof(PBEncResult));
    pbResult.message = weilapb_getMessageByCommandId(WL_Service_ServiceID_SERVICE_GROUP, commandId);

    if (pServiceMessage) {
        pServiceMessage->has_groupMessage = true;
        memcpy(&pServiceMessage->groupMessage, pParam, sizeof(WL_Group_GroupMessage));
        if (weilapb_encodeWeilaMsg(pServiceMessage, &pbResult)) {
            PB_FREE(pServiceMessage);
            return pbResult;
        } else {
            PB_FREE(pServiceMessage);
            pbResult.errCode = ERR_ENCODE;
        }
    } else {
        pbResult.errCode = ERR_OUT_OF_MEMORY;
    }

    return pbResult;
}

PBEncResult weilapb_buildGetGroupVersionReq() {
    WL_Group_GroupMessage wlGroupGroupMessage  = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupVersion = true;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_GROUPVERSION, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGetGroupAttributeReq(PB_UINT64 groupId) {
    WL_Group_GroupMessage wlGroupGroupMessage            = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupAttribute         = true;
    wlGroupGroupMessage.reqGetGroupAttribute.has_groupId = true;
    wlGroupGroupMessage.reqGetGroupAttribute.groupId     = groupId;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_GROUPATTRIBUTE, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildCreateGroupReq(PB_CHAR*   pName,
                                        PB_UINT16  groupType,
                                        PB_UINT16  publicType,
                                        PB_CHAR*   pAvatar,
                                        PB_UINT32* pMemberIdList,
                                        PB_UINT32  memberCount) {
    PBFieldData nameField;
    PBFieldData avatarField;
    PBFieldData memberIdField;

    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqCreateGroup    = true;

    weilapb_initEncDataItem(&nameField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pName), pName);
    weilapb_setEncCallback(&nameField, &wlGroupGroupMessage.reqCreateGroup.name, PB_NULL);

    weilapb_initEncDataItem(&avatarField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pAvatar), pAvatar);
    weilapb_setEncCallback(&avatarField, &wlGroupGroupMessage.reqCreateGroup.avatar, PB_NULL);

    if (pMemberIdList && memberCount) {
        weilapb_initEncDataItem(&memberIdField, PB_DATA_TYPE_ARRAY_UINT32, memberCount, pMemberIdList);
        weilapb_setEncCallback(&memberIdField, &wlGroupGroupMessage.reqCreateGroup.memberIdList, PB_NULL);
    }

    wlGroupGroupMessage.reqCreateGroup.has_type       = true;
    wlGroupGroupMessage.reqCreateGroup.type           = groupType;
    wlGroupGroupMessage.reqCreateGroup.has_publicType = true;
    wlGroupGroupMessage.reqCreateGroup.publicType     = publicType;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_CREATE_GROUP, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildChangeGroupAttrReq(PB_UINT32 groupId, PBChangeGroupAttr* pChangeGroupAttr) {
    PBEncResult           encResult;
    WL_Group_GroupMessage wlGroupGroupMessage       = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqChangeGroupAttribute = true;

    if (pChangeGroupAttr) {
        PBFieldData nameField;
        PBFieldData avatarField;
        PBFieldData descField;
        PBFieldData passwordField;

        if (pChangeGroupAttr->changeName) {
            weilapb_initEncDataItem(
                &nameField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pChangeGroupAttr->name), pChangeGroupAttr->name);
            weilapb_setEncCallback(&nameField, &wlGroupGroupMessage.reqChangeGroupAttribute.name, PB_NULL);
        }

        if (pChangeGroupAttr->changeAvatar) {
            weilapb_initEncDataItem(&avatarField,
                                    PB_DATA_TYPE_FIXED_SIZE_STRING,
                                    strlen(pChangeGroupAttr->avatar),
                                    pChangeGroupAttr->avatar);
            weilapb_setEncCallback(&avatarField, &wlGroupGroupMessage.reqChangeGroupAttribute.avatar, PB_NULL);
        }

        if (pChangeGroupAttr->changeDesc) {
            weilapb_initEncDataItem(
                &descField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pChangeGroupAttr->desc), pChangeGroupAttr->desc);
            weilapb_setEncCallback(&descField, &wlGroupGroupMessage.reqChangeGroupAttribute.desc, PB_NULL);
        }

        wlGroupGroupMessage.reqChangeGroupAttribute.has_groupId = true;
        wlGroupGroupMessage.reqChangeGroupAttribute.groupId     = groupId;

        wlGroupGroupMessage.reqChangeGroupAttribute.has_type = pChangeGroupAttr->changeGroupType;
        wlGroupGroupMessage.reqChangeGroupAttribute.type     = pChangeGroupAttr->groupType;

        wlGroupGroupMessage.reqChangeGroupAttribute.has_publicType = pChangeGroupAttr->changePublicType;
        wlGroupGroupMessage.reqChangeGroupAttribute.publicType     = pChangeGroupAttr->publicType;

        wlGroupGroupMessage.reqChangeGroupAttribute.has_burstType = pChangeGroupAttr->changeBurstType;
        wlGroupGroupMessage.reqChangeGroupAttribute.burstType     = pChangeGroupAttr->burstType;

        wlGroupGroupMessage.reqChangeGroupAttribute.has_ownerId = pChangeGroupAttr->changeOwnerId;
        wlGroupGroupMessage.reqChangeGroupAttribute.ownerId     = pChangeGroupAttr->ownerId;

        if (pChangeGroupAttr->changeAuthType) {
            wlGroupGroupMessage.reqChangeGroupAttribute.has_authType = pChangeGroupAttr->changeAuthType;
            wlGroupGroupMessage.reqChangeGroupAttribute.authType     = pChangeGroupAttr->authType;

            weilapb_initEncDataItem(&passwordField,
                                    PB_DATA_TYPE_FIXED_SIZE_STRING,
                                    strlen(pChangeGroupAttr->authPassword),
                                    pChangeGroupAttr->authPassword);
            weilapb_setEncCallback(&passwordField, &wlGroupGroupMessage.reqChangeGroupAttribute.authPassword, PB_NULL);
        }
        return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_CHANGE_GROUPATTRIBUTE, &wlGroupGroupMessage);
    } else {
        memset(&encResult, 0, sizeof(PBEncResult));
        encResult.errCode = ERR_INVALID_PARAMS;
    }

    return encResult;
}

PBEncResult weilapb_buildGetGroupInfoReq(PB_UINT32 groupId, PB_UINT32 memberVersion) {
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupInfo   = true;

    wlGroupGroupMessage.reqGetGroupInfo.has_groupId = true;
    wlGroupGroupMessage.reqGetGroupInfo.groupId     = groupId;

    wlGroupGroupMessage.reqGetGroupInfo.has_memberVersion = true;
    wlGroupGroupMessage.reqGetGroupInfo.memberVersion     = memberVersion;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_GROUPINFO, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildEmbeddedGetGroupVersionReq(PB_UINT32 limit) {
    WL_Group_GroupMessage wlGroupGroupMessage                = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqEmbeddedGetGroupVersion       = true;
    wlGroupGroupMessage.reqEmbeddedGetGroupVersion.has_limit = true;
    wlGroupGroupMessage.reqEmbeddedGetGroupVersion.limit     = limit;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_EMBEDDED_COMMAND_GET_GROUPVERSION, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildEmbeddedGetGroupInfoReq(PB_UINT64* pGroupIdList, PB_UINT32 count) {
    PBFieldData           groupIdField;
    WL_Group_GroupMessage wlGroupGroupMessage       = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqEmbeddedGetGroupInfo = true;

    if (pGroupIdList && count) {
        weilapb_initEncDataItem(&groupIdField, PB_DATA_TYPE_ARRAY_UINT64, count, pGroupIdList);
        weilapb_setEncCallback(&groupIdField, &wlGroupGroupMessage.reqEmbeddedGetGroupInfo.groupIds, PB_NULL);
    }

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_EMBEDDED_COMMAND_GET_GROUPINFO, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGetOnlineMemeberReq(PB_UINT32 groupId) {
    WL_Group_GroupMessage wlGroupGroupMessage       = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupOnlineMember = true;

    wlGroupGroupMessage.reqGetGroupOnlineMember.has_groupId = true;
    wlGroupGroupMessage.reqGetGroupInfo.groupId             = groupId;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_ONLINE_MEMBER, &wlGroupGroupMessage);
}

PBEncResult
    weilapb_buildChangeMemberInfoReq(PB_UINT64 groupId, PB_UINT32 memberId, PBChangeMemberInfo* pbChangeMemberInfo) {
    PBEncResult encResult;
    if (pbChangeMemberInfo) {
        PBFieldData           remarkField;
        WL_Group_GroupMessage wlGroupGroupMessage   = WL_Group_GroupMessage_init_zero;
        wlGroupGroupMessage.has_reqChangeMemberInfo = true;

        wlGroupGroupMessage.reqChangeMemberInfo.has_groupId = true;
        wlGroupGroupMessage.reqChangeMemberInfo.groupId     = groupId;

        wlGroupGroupMessage.reqChangeMemberInfo.has_memberId = true;
        wlGroupGroupMessage.reqChangeMemberInfo.memberId     = memberId;

        wlGroupGroupMessage.reqChangeMemberInfo.has_type = pbChangeMemberInfo->changeType;
        wlGroupGroupMessage.reqChangeMemberInfo.type     = pbChangeMemberInfo->memberType;

        wlGroupGroupMessage.reqChangeMemberInfo.has_shutupStatus   = pbChangeMemberInfo->changeSpeechPermission;
        wlGroupGroupMessage.reqChangeMemberInfo.shutupStatus       = pbChangeMemberInfo->speechPermission;
        wlGroupGroupMessage.reqChangeMemberInfo.has_shutupDuration = pbChangeMemberInfo->changeSpeechPermission;
        wlGroupGroupMessage.reqChangeMemberInfo.shutupDuration     = pbChangeMemberInfo->slientDuration;

        wlGroupGroupMessage.reqChangeMemberInfo.has_prority = pbChangeMemberInfo->changePriority;
        wlGroupGroupMessage.reqChangeMemberInfo.prority     = pbChangeMemberInfo->priority;

        wlGroupGroupMessage.reqChangeMemberInfo.has_shieldStatus = pbChangeMemberInfo->changeRecvStatus;
        wlGroupGroupMessage.reqChangeMemberInfo.shieldStatus     = pbChangeMemberInfo->recvStatus;

        wlGroupGroupMessage.reqChangeMemberInfo.has_locationShare = pbChangeMemberInfo->changeSharedLocationStatus;
        wlGroupGroupMessage.reqChangeMemberInfo.locationShare     = pbChangeMemberInfo->sharedLocationStatus;

        wlGroupGroupMessage.reqChangeMemberInfo.has_tts = pbChangeMemberInfo->changeTTSStatus;
        wlGroupGroupMessage.reqChangeMemberInfo.tts     = pbChangeMemberInfo->ttsStatus;

        weilapb_initEncDataItem(&remarkField,
                                PB_DATA_TYPE_FIXED_SIZE_STRING,
                                strlen(pbChangeMemberInfo->remark),
                                pbChangeMemberInfo->remark);
        weilapb_setEncCallback(&remarkField, &wlGroupGroupMessage.reqChangeMemberInfo.remark, PB_NULL);

        return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_ONLINE_MEMBER, &wlGroupGroupMessage);
    } else {
        memset(&encResult, 0, sizeof(PBEncResult));
        encResult.errCode = ERR_INVALID_PARAMS;
    }

    return encResult;
}

PBEncResult weilapb_buildGetGroupUserInfoReq(PB_UINT64  groupId,
                                             PB_UINT32* pUserIdList,
                                             PB_UINT32  listCount,
                                             PB_UINT16  memberType) {
    PBFieldData           userIdListField;
    WL_Group_GroupMessage wlGroupGroupMessage    = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetMemberUserInfo = true;

    wlGroupGroupMessage.reqGetMemberUserInfo.has_groupId = true;
    wlGroupGroupMessage.reqGetMemberUserInfo.groupId     = groupId;

    weilapb_initEncDataItem(&userIdListField, PB_DATA_TYPE_ARRAY_UINT32, listCount, pUserIdList);
    weilapb_setEncCallback(&userIdListField, &wlGroupGroupMessage.reqGetMemberUserInfo.userIdList, PB_NULL);

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_MEMBER_USERINFO, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildDelGroupMemberReq(PB_UINT64 groupId, PB_UINT32* pUserIdList, PB_UINT32 listCount) {
    PBFieldData           userIdListField;
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqDeleteMember   = true;

    wlGroupGroupMessage.reqDeleteMember.has_groupId = true;
    wlGroupGroupMessage.reqDeleteMember.groupId     = groupId;

    weilapb_initEncDataItem(&userIdListField, PB_DATA_TYPE_ARRAY_UINT32, listCount, pUserIdList);
    weilapb_setEncCallback(&userIdListField, &wlGroupGroupMessage.reqDeleteMember.userIdList, PB_NULL);

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_DELETE_MEMBER, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildDelGroupReq(PB_UINT64 groupId) {
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqDeleteGroup    = true;

    wlGroupGroupMessage.reqDeleteGroup.has_groupId = true;
    wlGroupGroupMessage.reqDeleteGroup.groupId     = groupId;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_DELETE_GROUP, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGetGroupInvitationInfoReq(PB_UINT32 latestUpdateTimestamp) {
    WL_Group_GroupMessage wlGroupGroupMessage     = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupInviteInfo = true;

    wlGroupGroupMessage.reqGetGroupInviteInfo.has_latestUpdated = true;
    wlGroupGroupMessage.reqGetGroupInviteInfo.latestUpdated     = latestUpdateTimestamp;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_GROUP_INVITEINFO, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGroupInviteReq(PB_UINT64 groupId, PB_UINT32* pUserIdList, PB_UINT32 listCount) {
    PBFieldData           userIdListField;
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGroupInvite    = true;

    wlGroupGroupMessage.reqGroupInvite.has_groupId = true;
    wlGroupGroupMessage.reqGroupInvite.groupId     = groupId;

    weilapb_initEncDataItem(&userIdListField, PB_DATA_TYPE_ARRAY_UINT32, listCount, pUserIdList);
    weilapb_setEncCallback(&userIdListField, &wlGroupGroupMessage.reqGroupInvite.userIdList, PB_NULL);

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GROUP_INVITE, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildAnswerGroupInviteReq(PB_UINT64 groupId, PB_UINT32 invitorId, PB_UINT16 answerStatus) {
    WL_Group_GroupMessage wlGroupGroupMessage    = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqAnswerGroupInvite = true;

    wlGroupGroupMessage.reqAnswerGroupInvite.has_groupId = true;
    wlGroupGroupMessage.reqAnswerGroupInvite.groupId     = groupId;

    wlGroupGroupMessage.reqAnswerGroupInvite.has_inviterId = true;
    wlGroupGroupMessage.reqAnswerGroupInvite.inviterId     = invitorId;

    wlGroupGroupMessage.reqAnswerGroupInvite.has_status = true;
    wlGroupGroupMessage.reqAnswerGroupInvite.status     = answerStatus;
    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_ANSWER_GROUP_INVITE, &wlGroupGroupMessage);
}

PBEncResult
    weilapb_buildGetGroupJoinInfoReq(PB_UINT64* pGroupIdList, PB_UINT32 listCount, PB_UINT32 latestUpdatedTimestamp) {
    PBFieldData           groupIdListField;
    WL_Group_GroupMessage wlGroupGroupMessage   = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupJoinInfo = true;

    wlGroupGroupMessage.reqGetGroupJoinInfo.has_latestUpdated = true;
    wlGroupGroupMessage.reqGetGroupJoinInfo.latestUpdated     = latestUpdatedTimestamp;

    weilapb_initEncDataItem(&groupIdListField, PB_DATA_TYPE_ARRAY_UINT64, listCount, pGroupIdList);
    weilapb_setEncCallback(&groupIdListField, &wlGroupGroupMessage.reqGetGroupJoinInfo.groupIds, PB_NULL);

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_GROUP_JOININFO, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildJoinGroupReq(PB_UINT64 groupId, PB_CHAR* pDetail, PB_CHAR* pPassword) {
    PBFieldData           detailField;
    PBFieldData           passwordField;
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGroupJoin      = true;

    wlGroupGroupMessage.reqGroupJoin.has_groupId = true;
    wlGroupGroupMessage.reqGroupJoin.groupId     = groupId;

    if (pDetail) {
        weilapb_initEncDataItem(&detailField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pDetail), pDetail);
        weilapb_setEncCallback(&detailField, &wlGroupGroupMessage.reqGroupJoin.detail, PB_NULL);
    }

    if (pPassword) {
        weilapb_initEncDataItem(&passwordField, PB_DATA_TYPE_FIXED_SIZE_STRING, strlen(pPassword), pPassword);
        weilapb_setEncCallback(&passwordField, &wlGroupGroupMessage.reqGroupJoin.password, PB_NULL);
    }

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GROUP_JOIN, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildAnswerGroupJoinReq(PB_UINT64 groupId, PB_UINT32 joinerId, PB_UINT16 answerStatus) {
    WL_Group_GroupMessage wlGroupGroupMessage  = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqAnswerGroupJoin = true;

    wlGroupGroupMessage.reqAnswerGroupJoin.has_groupId = true;
    wlGroupGroupMessage.reqAnswerGroupJoin.groupId     = groupId;

    wlGroupGroupMessage.reqAnswerGroupJoin.has_joinId = true;
    wlGroupGroupMessage.reqAnswerGroupJoin.joinId     = joinerId;

    wlGroupGroupMessage.reqAnswerGroupJoin.has_status = true;
    wlGroupGroupMessage.reqAnswerGroupJoin.status     = answerStatus;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_ANSWER_GROUP_JOIN, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGroupBroadcastReq(PB_UINT64 groupId, PB_UINT32 status) {
    WL_Group_GroupMessage wlGroupGroupMessage = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGroupBroadcast = true;

    wlGroupGroupMessage.reqGroupBroadcast.has_groupId = true;
    wlGroupGroupMessage.reqGroupBroadcast.groupId     = groupId;

    wlGroupGroupMessage.reqGroupBroadcast.has_status = true;
    wlGroupGroupMessage.reqGroupBroadcast.status     = status;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_BROADCAST, &wlGroupGroupMessage);
}

PBEncResult weilapb_buildGetGroupBlacklistReq(PB_UINT64 groupId, PB_UINT32 pageIndex, PB_UINT32 pageSize) {
    WL_Group_GroupMessage wlGroupGroupMessage    = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqGetGroupBlackList = true;

    wlGroupGroupMessage.reqGetGroupBlackList.has_groupId = true;
    wlGroupGroupMessage.reqGetGroupBlackList.groupId     = groupId;

    wlGroupGroupMessage.reqGetGroupBlackList.has_pageIndex = true;
    wlGroupGroupMessage.reqGetGroupBlackList.pageIndex     = pageIndex;

    wlGroupGroupMessage.reqGetGroupBlackList.has_pageSize = true;
    wlGroupGroupMessage.reqGetGroupBlackList.pageSize     = pageSize;

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_GET_BLACKLIST, &wlGroupGroupMessage);
}

extern PBEncResult weilapb_buildChangeGroupBlacklistReq(PB_UINT64  groupId,
                                                        PB_UINT32* pUserIdList,
                                                        PB_UINT32  listCount,
                                                        PB_UINT32  status) {
    PBFieldData           userIdListField;
    WL_Group_GroupMessage wlGroupGroupMessage       = WL_Group_GroupMessage_init_zero;
    wlGroupGroupMessage.has_reqChangeGroupBlackList = true;

    wlGroupGroupMessage.reqChangeGroupBlackList.has_groupId = true;
    wlGroupGroupMessage.reqChangeGroupBlackList.groupId     = groupId;

    wlGroupGroupMessage.reqChangeGroupBlackList.has_type = status;
    wlGroupGroupMessage.reqChangeGroupBlackList.type     = status;

    weilapb_initEncDataItem(&userIdListField, PB_DATA_TYPE_ARRAY_UINT32, listCount, pUserIdList);
    weilapb_setEncCallback(&userIdListField, &wlGroupGroupMessage.reqChangeGroupBlackList.userIdList, PB_NULL);

    return weilapb_buildGroupReq(WL_Group_GroupCommandId_GROUP_COMMAND_CHANGE_BLACKLIST, &wlGroupGroupMessage);
}
